<?php
/**
 * The control file of index module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class statistics extends control
{
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    public function index($date="")
    {
        if(!$date){
            $date = date('Y',time());
        }

        $this->view->category = $this->statistics->getbigcatecory();

        $startDate1    = "{$date}-01-01";
        $startDate2    = "{$date}-02-01";
        $startDate3    = "{$date}-03-01";
        $startDate4    = "{$date}-04-01";
        $startDate5    = "{$date}-05-01";
        $startDate6    = "{$date}-06-01";
        $startDate7    = "{$date}-07-01";
        $startDate8    = "{$date}-08-01";
        $startDate9    = "{$date}-09-01";
        $startDate10    = "{$date}-10-01";
        $startDate11    = "{$date}-11-01";
        $startDate12    = "{$date}-12-01";
        $this->view->data1 = $this->statistics->getcategorysum($startDate1);

        $this->view->data2 = $this->statistics->getcategorysum($startDate2);
        $this->view->data3 = $this->statistics->getcategorysum($startDate3);
        $this->view->data4 = $this->statistics->getcategorysum($startDate4);
        $this->view->data5 = $this->statistics->getcategorysum($startDate5);
        $this->view->data6 = $this->statistics->getcategorysum($startDate6);
        $this->view->data7 = $this->statistics->getcategorysum($startDate7);
        $this->view->data8 = $this->statistics->getcategorysum($startDate8);
        $this->view->data9 = $this->statistics->getcategorysum($startDate9);
        $this->view->data10 = $this->statistics->getcategorysum($startDate10);
        $this->view->data11 = $this->statistics->getcategorysum($startDate11);
        $this->view->data12 = $this->statistics->getcategorysum($startDate12);
        $this->view->title = $this->lang->statistics->index;

        $this->view->years = $this->loadModel('user')->getlang();
        $this->view->time = $date;
        $this->view->nowyears = date('Y',time());
        $this->display();
    }

    public function units($starttime=""){

        $date = time();
        $this->view->title = $this->lang->statistics->units;
        $this->view->category = $this->statistics->getbigcatecory();
        $date = date('Y',time());
        $this->view->startDate1    = "01-01";
        $this->view->startDate2    = "02-01";
        $this->view->startDate3    = "03-01";
        $this->view->startDate4    = "04-01";
        $this->view->startDate5    = "05-01";
        $this->view->startDate6    = "06-01";
        $this->view->startDate7    = "07-01";
        $this->view->startDate8    = "08-01";
        $this->view->startDate9    = "09-01";
        $this->view->startDate10    = "10-01";
        $this->view->startDate11    = "11-01";
        $this->view->startDate12    = "12-01";

        if(!$starttime){
            $nowdate = date('Y-m',time());
            $starttime    = "{$nowdate}-01";
        }
        $this->view->unit = $this->statistics->getunit($starttime);
        $ytime = date('Y',strtotime($starttime));
        $moth = date('m',strtotime($starttime));
        $this->view->years = $this->loadModel('user')->getlang();
        $time = $ytime;
        $this->view->month = $moth;
        $this->view->time = $time;
        $this->view->nowyears = date('Y',time());
        $this->display();
    }

    public function appraisal($date=""){
       if(!$date){
           $date = date('Y',time());
       }
        $this->view->title = $this->lang->statistics->appraisal;
        $this->view->unit = $this->statistics->getappraisal($date);

        $this->view->years = $this->loadModel('user')->getlang();
        $this->view->time = $date;
        $this->view->nowyears = date('Y',time());
        $this->display();
    }

    public function pstatis($unit="",$date=""){


        $this->view->category = $this->statistics->getbigcatecory();

        $startDate    = "{$date}-01-01";
        $this->view->users = $this->statistics->pstatis($unit,$startDate);
        $cname = $this->statistics->getunitname($unit);
        $time = $date.'年';
        $this->view->time = $time;
        $this->view->cname = $cname;
        $this->display();
    }

    public function qxingqing($idcard){

        $date = date('Y',time());
        $startDate    = "{$date}-01-01";
        $this->view->scategory = $this->statistics->qxingqing($idcard,$startDate);
        $username = $this->statistics->getusername($idcard);
        $sum = $this->statistics->getusersum($idcard,$startDate);
        $this->view->title = $date.'年'.$username.'共扣'.$sum.'分';
        $this->display();
    }

    public function ptype($idcard="",$bid){

        $date = date('Y',time());
        $startDate    = "{$date}-01-01";
        $this->view->scategory = $this->statistics->ptype($idcard,$startDate,$bid);
        $cname = $this->statistics->getcnamebyid($bid);
        $username = $this->statistics->getusername($idcard);
        $sum = $this->statistics->getusersum($idcard,$startDate,$bid);
        $this->view->title = $date.'年'.$username.$cname.'扣'.$sum.'分';

        $this->display();
    }

    public function pappraisal($uid,$type,$start,$end,$sum){

        $ytime = substr($start,0,4);
        $cname = $this->statistics->getunitname($uid);
        $scoretype = $this->lang->statistics->typeList[$type];
        $title = $ytime.'年'.$cname.$scoretype.$sum.'次';
        $this->view->title = $title;
        $this->view->scategory = $this->statistics->pappraisal($uid,$type,$start,$end);

        $this->display();

    }

    public function scategory($pid,$start,$end){


        //$scategory = $this->statistics->scategory($pid,$start,$end);
        $scategory = $this->statistics->scategoryt($pid,$start,$end);
        $this->view->scategory = $scategory;


        $ytime = substr($start,0,4);
        $moth = date('m',strtotime($start));
       $time = $ytime.'年'.$moth.'月';
        $cname = $this->statistics->getcnamebyid($pid);
       // $sum = $this->statistics->getsum($pid,$start,$end);
        $sum = $this->statistics->getsumt($pid,$start,$end);
        $title = $time.$cname.'共扣'.$sum.'分';
        $this->view->title = $title;
        $this->display();
    }





    public function punits($unitid,$start,$end){


        $scategory = $this->statistics->punits($unitid,$start,$end);

        $this->view->scategory = $scategory;
        $ytime = substr($start,0,4);
        $moth = date('m',strtotime($start));
        $time = $ytime.'年'.$moth.'月';
        $cname = $this->statistics->getunitname($unitid);
        $sum = $this->statistics->getunitsum($unitid,$start,$end);
        $title = $time.$cname.'共扣'.$sum.'分';
        $this->view->title = $title;
        $this->display();
    }

    public function cunits($unitid,$bid,$start,$end){


        $scategory = $this->statistics->cunits($unitid,$bid,$start,$end);

        $this->view->scategory = $scategory;
        $ytime = substr($start,0,4);
        $moth = date('m',strtotime($start));
        $time = $ytime.'年'.$moth.'月';
        $uname = $this->statistics->getunitname($unitid);
        $cname = $this->statistics->getcnamebyid($bid);
        $sum = $this->statistics->getunitcategorysum($unitid,$bid,$start,$end);
        $title = $time.$uname.$cname.'共扣'.$sum.'分';
        $this->view->title = $title;
        $this->display();
    }

    public function deductmarks(){

        $deductmarks = $this->statistics->getdeductmarks();
        print_r($deductmarks);
    }

    public function liandai(){

        $deductmarks = $this->statistics->getliandai();
        print_r($deductmarks);
    }

    public function setscore(){

//        $a = $this->statistics->setpscore();
//       $b = $this->statistics->setdscore();
//       $c = $this->statistics->setLscore();
//      $d = $this->statistics->setSscore();


    }

//    public function insertstatic(){
//
//        $a=$this->statistics->insertstatic();
//        $b=$this->statistics->insertlintstatic();
//        var_dump($a);
//        var_dump($b);
//    }

}
